From 664baa2b5e5247ab52b98710a2740f7de3b199a7 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 7 Sep 2016 18:38:19 -0700 Subject: [PATCH] Add rate limits for changing a page's content model The defaults are set to the same value as page moves. Change-Id: I72d6c35ecda475101c1c909715e4ba693dd214f6 --- includes/DefaultSettings.php | 5 +++++ includes/EditPage.php | 4 +++- includes/specials/SpecialChangeContentModel.php | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3bf838121e..bae74201ff 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5581,6 +5581,11 @@ $wgRateLimits = [ 'ip' => [ 8, 60 ], 'newbie' => [ 8, 60 ], ], + // Changing the content model of a page + 'editcontentmodel' => [ + 'newbie' => [ 2, 120 ], + 'user' => [ 8, 60 ], + ], ]; /** diff --git a/includes/EditPage.php b/includes/EditPage.php index b98c908b78..4e9aebaf63 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1836,7 +1836,9 @@ class EditPage { $status->value = self::AS_READ_ONLY_PAGE; return $status; } - if ( $wgUser->pingLimiter() || $wgUser->pingLimiter( 'linkpurge', 0 ) ) { + if ( $wgUser->pingLimiter() || $wgUser->pingLimiter( 'linkpurge', 0 ) + || ( $changingContentModel && $wgUser->pingLimiter( 'editcontentmodel' ) ) + ) { $status->fatal( 'actionthrottledtext' ); $status->value = self::AS_RATE_LIMITED; return $status; diff --git a/includes/specials/SpecialChangeContentModel.php b/includes/specials/SpecialChangeContentModel.php index ccbb2752ba..b37c47556f 100644 --- a/includes/specials/SpecialChangeContentModel.php +++ b/includes/specials/SpecialChangeContentModel.php @@ -191,6 +191,12 @@ class SpecialChangeContentModel extends FormSpecialPage { // Page doesn't exist, create an empty content object $newContent = ContentHandler::getForModelID( $data['model'] )->makeEmptyContent(); } + + // All other checks have passed, let's check rate limits + if ( $user->pingLimiter( 'editcontentmodel' ) ) { + throw new ThrottledError(); + } + $flags = $this->oldRevision ? EDIT_UPDATE : EDIT_NEW; $flags |= EDIT_INTERNAL; if ( $user->isAllowed( 'bot' ) ) { -- 2.20.1